package cn.senwill.controller;

import cn.senwill.domain.Result;
import cn.senwill.service.StockService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/stock") // 类级别的映射
public class StockController {

    @Value("${server.port}")
    private String port;

    private StockService stockService;

    @Autowired
    public void setStockService(StockService stockService) {
        this.stockService = stockService;
    }

    /**
     * 更新库存
     * {
     *     "product_id": 1,
     *     "used": 10
     * }
     * @param jsonObject
     * @return
     */
    @PostMapping(value = "update")
    @ResponseBody
    public Result update(@RequestBody JSONObject jsonObject) {
        return stockService.update(jsonObject);
    }
}